package com.springboot.aop2.service;

import com.springboot.aop2.dao.OperationLogDao;
import com.springboot.aop2.dao.UserDao;
import com.springboot.aop2.model.OperationLog;
import com.springboot.aop2.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author santiiny
 * @2019-11-25 20:54
 */
@Service
public class DemoService {

    @Autowired
    UserDao userDao;

    @Autowired
    OperationLogDao operationLogDao;

    /**
     * 通过 @Transactional 添加事务控制
     * @param name
     */
    @Transactional(rollbackFor = {})
    public void addUser(String name) {
        OperationLog log = new OperationLog();
        log.setContent("create user: " + name);
        operationLogDao.save(log);

        User user = new User();
        user.setName(name);
        userDao.save(user);
    }
}
